package com.example.zhish.viewpager_demo001;

import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by zhish on 2016/4/8.
 */
public class MyPagerAdapter extends PagerAdapter {

    public List<View> list;// = new ArrayList<View>();
    List<String> tabList;// = new ArrayList<String>();

    public MyPagerAdapter(List<View> list, List<String> tabList) {
        this.list = list;
        this.tabList = tabList;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
       container.addView(list.get(position));
        return list.get(position);
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView(list.get(position));
    }

    @Override
    public CharSequence getPageTitle(int position) {
         return tabList.get(position);
    }
}
